<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="车间" prop="workshop">
        <el-input
          v-model="queryParams.workshop"
          placeholder="请输入车间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="saleNum">
        <el-input
          v-model="queryParams.saleNum"
          placeholder="请输入销售订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划单号" prop="playNo">
        <el-input
          v-model="queryParams.playNo"
          placeholder="请输入计划单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['prodplan:feeding:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['prodplan:feeding:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleAudit"
          v-hasPermi="['prodplan:feeding:audit']"
          >审核</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUnAudit"
          v-hasPermi="['prodplan:feeding:unaudit']"
          >反审核</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['prodplan:feeding:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['prodplan:feeding:export']"
        >导出</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleChange"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleChangee"
          >变更</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="feedingList"
      @selection-change="handleSelectionChange"
      :default-sort="{ prop: 'date', order: 'descending' }"
      ref="tableDatas"
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="审核标志"
        align="center"
        prop="auditMark"
        :formatter="auditMarkFormat"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            capitalize(scope.row.auditMark)
          }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="投料单号"
        align="center"
        prop="goodsStagingno"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            scope.row.goodsStagingno
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="生产工单号"
        align="center"
        prop="prodorderNo"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            scope.row.prodorderNo
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="产品编码"
        align="center"
        prop="productCode"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            scope.row.productCode
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="产品名称"
        align="center"
        prop="productName"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            scope.row.productName
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="规格型号"
        align="center"
        prop="specModel"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{ scope.row.specModel }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="计划生产数量"
        align="center"
        prop="needQuantity"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            scope.row.needQuantity
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="单位"
        align="center"
        prop="unit"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{ scope.row.unit }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="子物料编码"
        align="center"
        prop="goodsCode"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="物料名称"
        align="center"
        prop="goodsName"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="物料规格"
        align="center"
        prop="goodsModel"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="单位用量"
        align="center"
        prop="unitDosage"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="标准用量"
        align="center"
        prop="standardDosage"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="损耗率"
        align="center"
        prop="lossRate"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="损耗数量"
        align="center"
        prop="lossnum"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="应发数量"
        align="center"
        prop="issuedQuantity"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="已领数量"
        align="center"
        prop="receivedQuantity"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="报废数量"
        align="center"
        prop="scrapQuantity"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            scope.row.scrapQuantity
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="补料数量"
        align="center"
        prop="replenQuantity"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="物料单位"
        align="center"
        prop="goodsUnit"
        sortable
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="销售订单号"
        align="center"
        prop="saleNum"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{ scope.row.saleNum }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="计划单号"
        align="center"
        prop="playNo"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{ scope.row.playNo }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="备料状态"
        align="center"
        prop="stockState"
        :formatter="stockStateFormat"
        sortable
        :show-overflow-tooltip="true"
      />
      <!-- <el-table-column label="单据状态" align="center" prop="docStatus" :formatter="docStatusFormat" sortable  :show-overflow-tooltip="true"/>
      <el-table-column label="执行状态" align="center" prop="exeStatus" :formatter="exeStatusFormat" sortable  :show-overflow-tooltip="true"/> -->
      <el-table-column
        label="生产类型"
        align="center"
        prop="prodType"
        :formatter="prodTypeFormat"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{ scope.row.prodType }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="车间"
        align="center"
        prop="workshop"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{ scope.row.workshop }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="工单类型"
        align="center"
        prop="workorderType"
        :formatter="workorderTypeFormat"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            scope.row.workorderType
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="计划需求数量"
        align="center"
        prop="quantity"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{ scope.row.quantity }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="计划发料日期"
        align="center"
        prop="plannedIssuedate"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.plannedIssuedate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="实际发料日期"
        align="center"
        prop="actualIssuedate"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualIssuedate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="制单日期"
        align="center"
        prop="preparationDate"
        sortable
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-show="IsHidden(scope.$index)">{{
            parseTime(scope.row.preparationDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column label="物料id" align="center" prop="goodsId" sortable  /> -->

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['prodplan:feeding:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['prodplan:feeding:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改投料管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="工单类型" prop="workorderType">
          <el-select v-model="form.workorderType" placeholder="请选择工单类型">
            <el-option
              v-for="dict in workorderTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品id" prop="productId">
          <el-input v-model="form.productId" placeholder="请输入产品id" />
        </el-form-item>
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="规格型号" prop="specModel">
          <el-input v-model="form.specModel" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="车间" prop="workshop">
          <el-input v-model="form.workshop" placeholder="请输入车间" />
        </el-form-item>
        <el-form-item label="审核标志" prop="auditMark">
          <el-select v-model="form.auditMark" placeholder="请选择审核标志">
            <el-option
              v-for="dict in auditMarkOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="auditMan">
          <el-input v-model="form.auditMan" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="审核日期" prop="auditDate">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form.auditDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择审核日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="物料id" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="请输入物料id" />
        </el-form-item>
        <el-form-item label="物料名称" prop="goodsName">
          <el-input v-model="form.goodsName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="物料规格型号" prop="goodsModel">
          <el-input
            v-model="form.goodsModel"
            placeholder="请输入物料规格型号"
          />
        </el-form-item>
        <el-form-item label="物料编码" prop="goodsCode">
          <el-input v-model="form.goodsCode" placeholder="请输入物料编码" />
        </el-form-item>
        <el-form-item label="物料单位" prop="goodsUnit">
          <el-input v-model="form.goodsUnit" placeholder="请输入物料单位" />
        </el-form-item>
        <el-form-item label="应投数量" prop="yfNum">
          <el-input v-model="form.yfNum" placeholder="请输入应投数量" />
        </el-form-item>
        <el-form-item label="单位用量" prop="unitDosage">
          <el-input v-model="form.unitDosage" placeholder="请输入单位用量" />
        </el-form-item>
        <el-form-item label="执行状态" prop="exeStatus">
          <el-select v-model="form.exeStatus" placeholder="请选择执行状态">
            <el-option
              v-for="dict in exeStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生产类型" prop="prodType">
          <el-select v-model="form.prodType" placeholder="请选择生产类型">
            <el-option
              v-for="dict in prodTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标准用量" prop="standardDosage">
          <el-input
            v-model="form.standardDosage"
            placeholder="请输入标准用量"
          />
        </el-form-item>
        <el-form-item label="应发数量" prop="issuedQuantity">
          <el-input
            v-model="form.issuedQuantity"
            placeholder="请输入应发数量"
          />
        </el-form-item>
        <el-form-item label="已领数量" prop="receivedQuantity">
          <el-input
            v-model="form.receivedQuantity"
            placeholder="请输入已领数量"
          />
        </el-form-item>
        <el-form-item label="报废数量" prop="scrapQuantity">
          <el-input v-model="form.scrapQuantity" placeholder="请输入报废数量" />
        </el-form-item>
        <el-form-item label="补料数量" prop="replenQuantity">
          <el-input
            v-model="form.replenQuantity"
            placeholder="请输入补料数量"
          />
        </el-form-item>
        <el-form-item label="损耗率" prop="lossRate">
          <el-input v-model="form.lossRate" placeholder="请输入损耗率" />
        </el-form-item>
        <el-form-item label="物料类型" prop="goodsType">
          <el-select v-model="form.goodsType" placeholder="请选择物料类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="生产工单号" prop="prodorderNo">
          <el-input v-model="form.prodorderNo" placeholder="请输入生产工单号" />
        </el-form-item>
        <el-form-item label="投料单号" prop="goodsStagingno">
          <el-input
            v-model="form.goodsStagingno"
            placeholder="请输入投料单号"
          />
        </el-form-item>
        <el-form-item label="销售订单号" prop="saleNum">
          <el-input v-model="form.saleNum" placeholder="请输入销售订单号" />
        </el-form-item>
        <el-form-item label="计划单号" prop="playNo">
          <el-input v-model="form.playNo" placeholder="请输入计划单号" />
        </el-form-item>
        <el-form-item label="计划发料日期" prop="plannedIssuedate">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form.plannedIssuedate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择计划发料日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际发料日期" prop="actualIssuedate">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form.actualIssuedate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择实际发料日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="制单日期" prop="preparationDate">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form.preparationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择制单日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态类型" prop="stateType">
          <el-select v-model="form.stateType" placeholder="请选择状态类">
            <el-option
              v-for="dict in stateTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备料状态" prop="stockState">
          <el-select v-model="form.stockState" placeholder="请选择备料状态">
            <el-option
              v-for="dict in stockStateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发料仓库" prop="issueWarehouse">
          <el-input
            v-model="form.issueWarehouse"
            placeholder="请输入发料仓库"
          />
        </el-form-item>
        <el-form-item label="发料人" prop="issuedBy">
          <el-input v-model="form.issuedBy" placeholder="请输入发料人" />
        </el-form-item>
        <el-form-item label="发料时间" prop="issueTime">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form.issueTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择发料时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收料仓库" prop="receiveWarehouse">
          <el-input
            v-model="form.receiveWarehouse"
            placeholder="请输入收料仓库"
          />
        </el-form-item>
        <el-form-item label="收料人" prop="receiveBy">
          <el-input v-model="form.receiveBy" placeholder="请输入收料人" />
        </el-form-item>
        <el-form-item label="收料时间" prop="receiveTime">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form.receiveTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择收料时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单号" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="级别名称" prop="levelName">
          <el-input v-model="form.levelName" placeholder="请输入级别名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="调拨状态" prop="transferStatus">
          <el-select v-model="form.transferStatus" placeholder="请选择调拨状态">
            <el-option
              v-for="dict in transferStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单据状态" prop="documentStatus">
          <el-select v-model="form.documentStatus" placeholder="请选择单据状态">
            <el-option
              v-for="dict in documentStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改投料管理对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openChange"
      width="1000px"
      append-to-body
    >
      <el-form ref="formChange" :model="formChange" label-width="90px">
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="产品编码" prop="productCode">
              <el-input v-model="formChange.productCode" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="formChange.productName" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格型号" prop="specModel">
              <el-input v-model="formChange.specModel" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="unit">
              <el-input v-model="formChange.unit" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车间" prop="workshop">
              <el-input v-model="formChange.workshop" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产工单号" prop="prodorderNo">
              <el-input v-model="formChange.prodorderNo" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="投料单号" prop="goodsStagingno">
              <el-input v-model="formChange.goodsStagingno" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="销售订单号" prop="saleNum">
              <el-input v-model="formChange.saleNum" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计划单号" prop="playNo">
              <el-input v-model="formChange.playNo" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料编码" prop="goodsCode">
              <el-select
                v-model="formChange.goodsCode"
                placeholder="请选择物料编码"
                style="width: 100%"
                @change="changeGoods"
              >
                <el-option
                  v-for="dict in goodsCodeList"
                  :key="dict.goodsCode"
                  :label="dict.goodsCode"
                  :value="dict.goodsCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料名称" prop="goodsName">
              <el-input v-model="formChange.goodsName" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料规格" prop="goodsModel">
              <el-input v-model="formChange.goodsModel" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料单位" prop="goodsUnit">
              <el-input v-model="formChange.goodsUnit" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应投数量" prop="investedQuantity">
              <el-input v-model="formChange.investedQuantity" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位用量" prop="unitDosage">
              <el-input v-model="formChange.unitDosage" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标准用量" prop="standardDosage">
              <el-input v-model="formChange.standardDosage" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应发数量" prop="issuedQuantity">
              <el-input v-model="formChange.issuedQuantity" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="已领数量" prop="receivedQuantity">
              <el-input
                v-model="formChange.receivedQuantity"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="补料数量" prop="replenQuantity">
              <el-input v-model="formChange.replenQuantity" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="损耗率" prop="lossRate">
              <el-input v-model="formChange.lossRate" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核人" prop="auditMan">
              <el-input
                v-model="formChange.auditMan"
                placeholder="请输入审核人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核日期" prop="auditDate">
              <el-date-picker
                clearable
                size="small"
                style="width: 200px"
                v-model="formChange.auditDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择审核日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitChangeForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改投料管理对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open1"
      width="1300px"
      append-to-body
    >
      <el-form ref="form1" :model="form1" :rules="rules1" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产工单" prop="prodorderNo">
              <el-input
                v-model="form1.prodorderNo"
                placeholder="请输入生产工单"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投料单号" prop="goodsStagingno">
              <el-input
                v-model="form1.goodsStagingno"
                placeholder="请输入投料单号"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="产品编码" prop="productCode">
              <el-input
                v-model="form1.productCode"
                placeholder="请输入产品编码"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="产品名称" prop="productName">
              <el-input
                v-model="form1.productName"
                placeholder="请输入产品名称"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="规格型号" prop="specModel">
              <el-input
                v-model="form1.specModel"
                placeholder="请输入规格型号"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="单位" prop="unit">
              <el-input
                v-model="form1.unit"
                placeholder="请输入单位"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-table
          v-loading="loading"
          :data="selectNo"
          @selection-change="handleSelectionChange"
          :default-sort="{ prop: 'date', order: 'descending' }"
          ref="tableDatas"
        >
          <el-table-column
            label="子物料编码"
            align="center"
            prop="goodsCode"
            sortable
            :show-overflow-tooltip="true"
            width="150"
          >
            <template scope="scope">
                <el-input
                  v-model="scope.row.goodsCode"
                  placeholder="请选择子物料编码"
                  style="width: 100%"
                >
                </el-input>
            </template>
          </el-table-column>
          <el-table-column
            label="物料名称"
            align="center"
            prop="goodsName"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="物料规格"
            align="center"
            prop="goodsModel"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="单位用量"
            align="center"
            prop="unitDosage"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="标准用量"
            align="center"
            prop="standardDosage"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="损耗率"
            align="center"
            prop="lossRate"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="损耗数量"
            align="center"
            prop="lossnum"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="应发数量"
            align="center"
            prop="issuedQuantity"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="已领数量"
            align="center"
            prop="receivedQuantity"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="报废数量"
            align="center"
            prop="scrapQuantity"
            sortable
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="IsHidden(scope.$index)">{{
                scope.row.scrapQuantity
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="补料数量"
            align="center"
            prop="replenQuantity"
            sortable
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="物料单位"
            align="center"
            prop="goodsUnit"
            sortable
            :show-overflow-tooltip="true"
          />
          <!-- <el-table-column
            label="销售订单号"
            align="center"
            prop="saleNum"
            sortable
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="IsHidden(scope.$index)">{{
                scope.row.saleNum
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="计划单号"
            align="center"
            prop="playNo"
            sortable
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="IsHidden(scope.$index)">{{
                scope.row.playNo
              }}</span>
            </template>
          </el-table-column> -->
          <el-table-column
            label="备料状态"
            align="center"
            prop="stockState"
            :formatter="stockStateFormat"
            sortable
            :show-overflow-tooltip="true"
          />
          <!-- <el-table-column label="单据状态" align="center" prop="docStatus" :formatter="docStatusFormat" sortable  :show-overflow-tooltip="true"/>
      <el-table-column label="执行状态" align="center" prop="exeStatus" :formatter="exeStatusFormat" sortable  :show-overflow-tooltip="true"/> -->
          <el-table-column
            label="生产类型"
            align="center"
            prop="prodType"
            :formatter="prodTypeFormat"
            sortable
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="IsHidden(scope.$index)">{{
                scope.row.prodType
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="车间"
            align="center"
            prop="workshop"
            sortable
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="IsHidden(scope.$index)">{{
                scope.row.workshop
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="工单类型"
            align="center"
            prop="workorderType"
            :formatter="workorderTypeFormat"
            sortable
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="IsHidden(scope.$index)">{{
                scope.row.workorderType
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="计划需求数量"
            align="center"
            prop="quantity"
            sortable
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="IsHidden(scope.$index)">{{
                scope.row.quantity
              }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import {
  listFeeding,
  getFeeding,
  delFeeding,
  addFeeding,
  updateFeeding,
  exportFeeding,
  audit,
  unAudit,
  getChange,
  getNo,
} from "@/api/prodplan/feeding";
import { listReplace } from "@/api/base/replace.js";
export default {
  name: "Feeding",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投料管理表格数据
      feedingList: [],
      //变更窗口
      selectNo: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 工单类型(0正常，1超产，2返工)字典
      workorderTypeOptions: [],
      // 审核标志字典
      auditMarkOptions: [],
      // 执行状态字典
      exeStatusOptions: [],
      // 生产类型(0普通订单，1新增订单，2MRP拉取)字典
      prodTypeOptions: [],
      // 状态类型(0=良品 1=不良品 2=待检品)字典
      stateTypeOptions: [],
      // 备料状态字典
      stockStateOptions: [],
      // 调拨状态(1=待调拨，2=调拨中，3=已完成)字典
      transferStatusOptions: [],
      // 单据状态(1=创建，2=完成)字典
      documentStatusOptions: [],
      //存放选中值的数组
      multipleTable: [],
      //合并记录的行列
      rowspans: [],
      //记录需要合并的行位置
      posi: 0,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workorderType: undefined,
        productId: undefined,
        productCode: undefined,
        productName: undefined,
        specModel: undefined,
        unit: undefined,
        workshop: undefined,
        auditMark: undefined,
        auditMan: undefined,
        auditDate: undefined,
        quantity: undefined,
        needQuantity: undefined,
        goodsId: undefined,
        goodsName: undefined,
        goodsModel: undefined,
        goodsCode: undefined,
        goodsUnit: undefined,
        yfNum: undefined,
        unitDosage: undefined,
        docStatus: undefined,
        exeStatus: undefined,
        prodType: undefined,
        standardDosage: undefined,
        issuedQuantity: undefined,
        receivedQuantity: undefined,
        scrapQuantity: undefined,
        replenQuantity: undefined,
        lossRate: undefined,
        goodsType: undefined,
        prodorderNo: undefined,
        goodsStagingno: undefined,
        saleNum: undefined,
        playNo: undefined,
        plannedIssuedate: undefined,
        actualIssuedate: undefined,
        preparationDate: undefined,
        stateType: undefined,
        stockState: undefined,
        issueWarehouse: undefined,
        issuedBy: undefined,
        issueTime: undefined,
        receiveWarehouse: undefined,
        receiveBy: undefined,
        receiveTime: undefined,
        orderNum: undefined,
        levelName: undefined,
        createTime: undefined,
        createUser: undefined,
        updateTime: undefined,
        updateUser: undefined,
        isDel: undefined,
        commentUnit: undefined,
        remark: undefined,
        standardNum: undefined,
        planfeedNum: undefined,
        menuNum: undefined,
        basicunitInnum: undefined,
        inworkNum: undefined,
        consumNum: undefined,
        recoil: undefined,
        batch: undefined,
        lineorderCode: undefined,
        entryNum: undefined,
        basicunitNum: undefined,
        commentunitNum: undefined,
        workcompany: undefined,
        forbidden: undefined,
        subgoodsType: undefined,
        subgoodsCode: undefined,
        basicUnit: undefined,
        keyParts: undefined,
        useStatus: undefined,
        basicunitDosage: undefined,
        basicunitOutnum: undefined,
        basicunitBzdosage: undefined,
        realLossrate: undefined,
        basicLossnum: undefined,
        lossnum: undefined,
        basicplanNum: undefined,
        basicunitQuantity: undefined,
        basicunitScrapnum: undefined,
        scrapnum: undefined,
        basicunitConsumnum: undefined,
        basicunitInworknum: undefined,
        workProcess: undefined,
        workStation: undefined,
        lockFlag: undefined,
        lockNum: undefined,
        basicunitLocknum: undefined,
        basicunitUpnum: undefined,
        makeupNum: undefined,
        processNum: undefined,
        customerBom: undefined,
        allocatedQuantity: undefined,
        allocatedNum: undefined,
        transferQuantity: undefined,
        transferNum: undefined,
        becomeQuantity: undefined,
        planMode: undefined,
        printNumber: undefined,
        teackNumber: undefined,
        locationNumber: undefined,
        returnDimension: undefined,
        returnQuantity: undefined,
        productProperties: undefined,
        propertiesCode: undefined,
        materialProperties: undefined,
        materialCode: undefined,
        releaseWorkshop: undefined,
        customerItem: undefined,
        mnemonicCode: undefined,
        transferStatus: undefined,
        documentStatus: undefined,
        upgoodsNum: undefined,
        existReplace: undefined,
        source: undefined,
        prodLine: undefined,
        team: undefined,
        frequency: undefined,
      },
      // 表单参数
      form: {},
      form1: {},
      openChange: false,
      formChange: {},
      open1: false,
      goodsCodeList: [], //替代关系
      // 表单校验
      rules: {},
      rules1: {},
    };
  },

  created() {
    this.getList();

    this.getDicts("prodplan_feeding_workorder_type").then((response) => {
      this.workorderTypeOptions = response.data;
    });
    this.getDicts("prodplan_feeding_audit_mark").then((response) => {
      this.auditMarkOptions = response.data;
    });
    this.getDicts("prodplan_workorder_doc_status").then((response) => {
      this.docStatusOptions = response.data;
    });
    this.getDicts("prodplan_feeding_exe_status").then((response) => {
      this.exeStatusOptions = response.data;
    });
    this.getDicts("prodplan_feeding_prod_type").then((response) => {
      this.prodTypeOptions = response.data;
    });
    this.getDicts("prodplan_feeding_state_type").then((response) => {
      this.stateTypeOptions = response.data;
    });
    this.getDicts("prodplan_feeding_stock_state").then((response) => {
      this.stockStateOptions = response.data;
    });
    this.getDicts("prodplan_feeding_transfer_status").then((response) => {
      this.transferStatusOptions = response.data;
    });
    this.getDicts("prodplan_feeding_document_status").then((response) => {
      this.documentStatusOptions = response.data;
    });
  },
  methods: {
    capitalize: function (value) {
      return this.selectDictLabel(this.auditMarkOptions, value);
    },

    /** 查询投料管理列表 */
    getList() {
      this.loading = true;
      listFeeding(this.queryParams).then((response) => {
        this.feedingList = response.rows;
        for (let i in this.feedingList) {
          if (i == 0) {
            //1代表真 显示     0代表假 隐藏
            this.rowspans.push(1);
            // this.posi = 0;
          } else {
            if (
              this.feedingList[i].prodorderNo ===
              this.feedingList[i - 1].prodorderNo
            ) {
              this.rowspans.push(0);
            } else {
              this.rowspans.push(1);
            }
          }
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    IsHidden(rowIndex) {
      //console.log(rowIndex);
      if (this.rowspans[rowIndex] == 1) {
        return true;
      } else {
        return false;
      }
    },
    // 工单类型(0正常，1超产，2返工)字典翻译
    workorderTypeFormat(row, column) {
      return this.selectDictLabel(this.workorderTypeOptions, row.workorderType);
    },
    // 审核标志字典翻译
    auditMarkFormat(row, column) {
      return this.selectDictLabel(this.auditMarkOptions, row.auditMark);
    },
    // 单据状态(0正常，1挂起，2关闭)字典翻译
    docStatusFormat(row, column) {
      return this.selectDictLabel(this.docStatusOptions, row.docStatus);
    },
    // 执行状态字典翻译
    exeStatusFormat(row, column) {
      return this.selectDictLabel(this.exeStatusOptions, row.exeStatus);
    },
    // 生产类型(0普通订单，1新增订单，2MRP拉取)字典翻译
    prodTypeFormat(row, column) {
      return this.selectDictLabel(this.prodTypeOptions, row.prodType);
    },
    // 状态类型(0=良品 1=不良品 2=待检品)字典翻译
    stateTypeFormat(row, column) {
      return this.selectDictLabel(this.stateTypeOptions, row.stateType);
    },
    // 备料状态字典翻译
    stockStateFormat(row, column) {
      return this.selectDictLabel(this.stockStateOptions, row.stockState);
    },
    // 调拨状态(1=待调拨，2=调拨中，3=已完成)字典翻译
    transferStatusFormat(row, column) {
      return this.selectDictLabel(
        this.transferStatusOptions,
        row.transferStatus
      );
    },
    // 单据状态(1=创建，2=完成)字典翻译
    documentStatusFormat(row, column) {
      return this.selectDictLabel(
        this.documentStatusOptions,
        row.documentStatus
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open1 = false;
      this.openChange = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        feedingId: undefined,
        workorderType: undefined,
        productId: undefined,
        productCode: undefined,
        productName: undefined,
        specModel: undefined,
        unit: undefined,
        workshop: undefined,
        auditMark: undefined,
        auditMan: undefined,
        auditDate: undefined,
        quantity: undefined,
        needQuantity: undefined,
        goodsId: undefined,
        goodsName: undefined,
        goodsModel: undefined,
        goodsCode: undefined,
        goodsUnit: undefined,
        yfNum: undefined,
        unitDosage: undefined,
        docStatus: undefined,
        exeStatus: undefined,
        prodType: undefined,
        standardDosage: undefined,
        issuedQuantity: undefined,
        receivedQuantity: undefined,
        scrapQuantity: undefined,
        replenQuantity: undefined,
        lossRate: undefined,
        goodsType: undefined,
        prodorderNo: undefined,
        goodsStagingno: undefined,
        saleNum: undefined,
        playNo: undefined,
        plannedIssuedate: undefined,
        actualIssuedate: undefined,
        preparationDate: undefined,
        stateType: undefined,
        stockState: undefined,
        issueWarehouse: undefined,
        issuedBy: undefined,
        issueTime: undefined,
        receiveWarehouse: undefined,
        receiveBy: undefined,
        receiveTime: undefined,
        orderNum: undefined,
        levelName: undefined,
        createTime: undefined,
        createUser: undefined,
        updateTime: undefined,
        updateUser: undefined,
        isDel: undefined,
        commentUnit: undefined,
        remark: undefined,
        standardNum: undefined,
        planfeedNum: undefined,
        menuNum: undefined,
        basicunitInnum: undefined,
        inworkNum: undefined,
        consumNum: undefined,
        recoil: undefined,
        batch: undefined,
        lineorderCode: undefined,
        entryNum: undefined,
        basicunitNum: undefined,
        commentunitNum: undefined,
        workcompany: undefined,
        forbidden: undefined,
        subgoodsType: undefined,
        subgoodsCode: undefined,
        basicUnit: undefined,
        keyParts: undefined,
        useStatus: "0",
        basicunitDosage: undefined,
        basicunitOutnum: undefined,
        basicunitBzdosage: undefined,
        realLossrate: undefined,
        basicLossnum: undefined,
        lossnum: undefined,
        basicplanNum: undefined,
        basicunitQuantity: undefined,
        basicunitScrapnum: undefined,
        scrapnum: undefined,
        basicunitConsumnum: undefined,
        basicunitInworknum: undefined,
        workProcess: undefined,
        workStation: undefined,
        lockFlag: undefined,
        lockNum: undefined,
        basicunitLocknum: undefined,
        basicunitUpnum: undefined,
        makeupNum: undefined,
        processNum: undefined,
        customerBom: undefined,
        allocatedQuantity: undefined,
        allocatedNum: undefined,
        transferQuantity: undefined,
        transferNum: undefined,
        becomeQuantity: undefined,
        planMode: undefined,
        printNumber: undefined,
        teackNumber: undefined,
        locationNumber: undefined,
        returnDimension: undefined,
        returnQuantity: undefined,
        productProperties: undefined,
        propertiesCode: undefined,
        materialProperties: undefined,
        materialCode: undefined,
        releaseWorkshop: undefined,
        customerItem: undefined,
        mnemonicCode: undefined,
        transferStatus: undefined,
        documentStatus: undefined,
        upgoodsNum: undefined,
        existReplace: undefined,
        source: undefined,
        prodLine: undefined,
        team: undefined,
        frequency: undefined,
      };
      this.formChange = {
        feedingId: undefined,
        workorderType: undefined,
        productId: undefined,
        productCode: undefined,
        productName: undefined,
        specModel: undefined,
        unit: undefined,
        workshop: undefined,
        auditMark: undefined,
        auditMan: undefined,
        auditDate: undefined,
        quantity: undefined,
        goodsId: undefined,
        goodsName: undefined,
        goodsModel: undefined,
        goodsCode: undefined,
        goodsUnit: undefined,
        investedQuantity: undefined,
        unitDosage: undefined,
        docStatus: undefined,
        exeStatus: undefined,
        prodType: undefined,
        standardDosage: undefined,
        issuedQuantity: undefined,
        receivedQuantity: undefined,
        scrapQuantity: undefined,
        replenQuantity: undefined,
        lossRate: undefined,
        goodsType: undefined,
        prodorderNo: undefined,
        goodsStagingno: undefined,
        saleNum: undefined,
        playNo: undefined,
        plannedIssuedate: undefined,
        actualIssuedate: undefined,
        preparationDate: undefined,
        stateType: undefined,
        stockState: undefined,
        issueWarehouse: undefined,
        issuedBy: undefined,
        issueTime: undefined,
        receiveWarehouse: undefined,
        receiveBy: undefined,
        receiveTime: undefined,
        orderNum: undefined,
        levelName: undefined,
        createTime: undefined,
        createUser: undefined,
        updateTime: undefined,
        updateUser: undefined,
        isDel: undefined,
        commentUnit: undefined,
        remark: undefined,
        standardNum: undefined,
        planfeedNum: undefined,
        menuNum: undefined,
        basicunitInnum: undefined,
        inworkNum: undefined,
        consumNum: undefined,
        recoil: undefined,
        batch: undefined,
        lineorderCode: undefined,
        entryNum: undefined,
        basicunitNum: undefined,
        commentunitNum: undefined,
        workcompany: undefined,
        forbidden: undefined,
        subgoodsType: undefined,
        subgoodsCode: undefined,
        basicUnit: undefined,
        keyParts: undefined,
        useStatus: "0",
        basicunitDosage: undefined,
        basicunitOutnum: undefined,
        basicunitBzdosage: undefined,
        realLossrate: undefined,
        basicLossnum: undefined,
        lossnum: undefined,
        basicplanNum: undefined,
        basicunitQuantity: undefined,
        basicunitScrapnum: undefined,
        scrapnum: undefined,
        basicunitConsumnum: undefined,
        basicunitInworknum: undefined,
        workProcess: undefined,
        workStation: undefined,
        lockFlag: undefined,
        lockNum: undefined,
        basicunitLocknum: undefined,
        basicunitUpnum: undefined,
        makeupNum: undefined,
        processNum: undefined,
        customerBom: undefined,
        allocatedQuantity: undefined,
        allocatedNum: undefined,
        transferQuantity: undefined,
        transferNum: undefined,
        becomeQuantity: undefined,
        planMode: undefined,
        printNumber: undefined,
        teackNumber: undefined,
        locationNumber: undefined,
        returnDimension: undefined,
        returnQuantity: undefined,
        productProperties: undefined,
        propertiesCode: undefined,
        materialProperties: undefined,
        materialCode: undefined,
        releaseWorkshop: undefined,
        customerItem: undefined,
        mnemonicCode: undefined,
        transferStatus: undefined,
        documentStatus: undefined,
        upgoodsNum: undefined,
        existReplace: undefined,
        source: undefined,
        prodLine: undefined,
        team: undefined,
        frequency: undefined,
      };
      this.form1 = {
        goodsStagingno: undefined,
        prodorderNo: undefined,
        productCode: undefined,
        productName: undefined,
        specModel: undefined,
        unit: undefined,
      };
      this.resetForm("form");
      this.resetForm("formChange");
      this.resetForm("form1");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.feedingId);
      this.docStatus = selection.map((item) => item.docStatus);
      this.exeStatus = selection.map((item) => item.exeStatus);
      this.existReplace = selection.map((item) => item.existReplace);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.multipleTable = selection;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加投料管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const feedingId = row.feedingId || this.ids;
      getFeeding(feedingId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改投料管理";
      });
    },
    handleChangee() {
      var aa = this.multipleTable.map((item) => item.prodorderNo)[0];
      getNo(aa).then((response) => {
        console.log(response);
        this.open1 = true;
        this.form1 = response.rows[0];
        this.selectNo = response.rows;
        this.title = "变更投料管理";
        this.goodsList();
      });
    },
    handleChange(row) {
      const docStatus = this.docStatus;
      const exeStatus = this.exeStatus;
      const existReplace = this.existReplace;
      if (existReplace == "N") {
        this.msgSuccess("物料没有替代关系，不能进行变更");
        return false;
      }
      if (docStatus == "1" && docStatus == 1) {
        this.msgSuccess("单据状态为挂起，不能进行变更");
        return false;
      }
      if (
        (exeStatus == "3" && exeStatus == 3) ||
        (exeStatus == "4" && exeStatus == 4)
      ) {
        this.msgSuccess("执行状态为结案或者完工，不能进行变更");
        return false;
      }
      const feedingId = row.feedingId || this.ids;
      getFeeding(feedingId).then((response) => {
        this.formChange = response.data;
        this.openChange = true;
        this.title = "变更投料管理";
        this.goodsList();
      });
    },
    goodsList() {
      listReplace().then((response) => {
        this.goodsCodeList = response.rows;
      });
    },
    changeGoods(val) {
      this.queryParams.goodsCode = val;
      listReplace(this.queryParams).then((response) => {
        this.formChange.goodsModel = response.rows[0].specificationModel;
        this.formChange.goodsName = response.rows[0].goodsName;
        this.formChange.goodsId = response.rows[0].goodsId;
        this.formChange.goodsUnit = response.rows[0].unit;
      });
    },
    submitChangeForm() {
      this.formChange.auditMark = 0;
      getChange(this.formChange).then((response) => {
        this.msgSuccess("变更成功");
        this.openChange = false;
        this.queryParams.goodsCode = "";
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.feedingId != null) {
            updateFeeding(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFeeding(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var auditMark = this.multipleTable.map((item) => item.auditMark)[0];
      if (auditMark == 1) {
        this.msgSuccess("已审核不能删除");
        return;
      }
      const feedingIds = row.feedingId || this.ids;
      this.$confirm(
        '是否确认删除投料管理编号为"' + feedingIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delFeeding(feedingIds);
        })
        .then((response) => {
          this.getList();
          this.msgSuccess(response.msg);
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有投料管理数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportFeeding(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    //审核
    handleAudit(row) {
      this.reset();
      var auditMark = this.multipleTable.map((item) => item.auditMark)[0];
      if (auditMark == 1) {
        this.msgSuccess("已审核不能审核");
        return;
      }
      const feedingId = row.feedingId || this.ids;
      audit(feedingId).then((response) => {
        this.msgSuccess("审核成功");
        this.getList();
      });
    },
    //反审核
    handleUnAudit(row) {
      this.reset();
      var exeStatus = this.multipleTable.map((item) => item.exeStatus)[0];
      var upgoodsNum = this.multipleTable.map((item) => item.upgoodsNum)[0];
      if (exeStatus != 0 || exeStatus != 5) {
        this.msgSuccess("工单处于计划或计划确认才能反审核");
        return;
      }
      if (upgoodsNum != 0) {
        this.msgSuccess("已上过料不能反审核");
        return;
      }
      const feedingId = row.feedingId || this.ids;
      audit(feedingId).then((response) => {
        this.msgSuccess("反审核成功");
        this.getList();
      });
    },
  },
};
</script>
